import sys,glob
import subprocess

with open(sys.argv[1]) as fq:
    fq.readline()
    for i in fq:
        l = i.split('\t')
        reads = l[2].strip().replace(',','')
        if l[0].find('NC') > -1:
            if l[0].find('-CF') > -1:
                cfkk = glob.glob(f'/data/mNGS/runmngs/GZ/NCList/today/NC*-CF*.kk.ra.xls')[0]
                kk = glob.glob(f'{sys.argv[2]}/{l[0]}/*kk.ra.xls')[0]
                script = f'''mv {cfkk} /data/mNGS/runmngs/GZ/NCList/bak
                    cp {kk} /data/mNGS/runmngs/GZ/NCList/today/{l[0]}.{reads}.kk.ra.xls'''
                subprocess.run(script, shell=True)
            elif l[0].find('-D') > -1:
                DNAkk = glob.glob(f'/data/mNGS/runmngs/GZ/NCList/today/NC*-D*.kk.ra.xls')[0]
                kk = glob.glob(f'{sys.argv[2]}/{l[0]}/*kk.ra.xls')[0]
                script = f'''mv {DNAkk} /data/mNGS/runmngs/GZ/NCList/bak
                    cp {kk} /data/mNGS/runmngs/GZ/NCList/today/{l[0]}.{reads}.kk.ra.xls'''
                subprocess.run(script, shell=True)
            elif l[0].find('-R') > -1:
                RNAkk = glob.glob(f'/data/mNGS/runmngs/GZ/NCList/today/NC*-R*.kk.ra.xls')[0]
                kk = glob.glob(f'{sys.argv[2]}/{l[0]}/*kk.ra.xls')[0]
                script = f'''mv {RNAkk} /data/mNGS/runmngs/GZ/NCList/bak
                    cp {kk} /data/mNGS/runmngs/GZ/NCList/today/{l[0]}.{reads}.kk.ra.xls'''
                subprocess.run(script, shell=True)